package com.mydemo;

import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

public class Producer {

    public static void main(String[] args) throws Exception{

        Properties properties = new Properties();
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"localhost:9092");
        properties.put(ProducerConfig.ACKS_CONFIG,"all");
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());

        KafkaProducer<String,String> producer = new KafkaProducer<String, String>(properties);

        String string = "{\"QR_NO\":\"6226598236043073200\",\"MCHNT_CD\":\"302440154110016\",\"RESP_CD\":\"0000000\",\"TRANS_IDX\":\"16200529492965180681\",\"EXT_NAME_SM3\":\"\",\"ACQ_NTF_ST\":\"0\",\"EXT_TRANS_INDUSTRY_APP_INF_SM3\":\"\",\"PHONE_NO\":\"15827401266\",\"PROC_SYS\":\"01\",\"ORG_SYS_TM\":\"\",\"EXT_CARD_BIN\":\"6222985106\",\"APP_NTF_ST\":\"0\",\"COUNTRY_CD\":\"156\",\"APP_INS_ID_CD\":\"00250001\",\"FWD_INS_ID_CD\":\"00049993\",\"MER_TRANS_INDEX\":\"LOTUS105426267\",\"RESP_MSG\":\"\",\"SETTLE_DT\":\"0529\",\"SETTLE_MD\":\"1\",\"ISS_INS_ID_CD\":\"04105840\",\"AREA_CD\":\"5800\",\"CDHD_TRANS_AT\":\"0\",\"EXT_MOBILE\":\"15827401266\",\"MCHNT_TP\":\"5411\",\"CONV_RT\":\"\",\"EXT_PRI_ACCT_NO_SM3\":\"902c9edf374f3c36c550bb8a7b3c1e36e5ac36e9a24b82132011221bf5ede4a7\",\"CDHD_CONV_RT\":\"\",\"SUB_MCHNT_CD\":\"\",\"ISS_HEAD\":\"04105840\",\"MCHNT_ORDER_ID\":\"662005291341362929188\",\"PROC_ST\":\"00\",\"PROC_CD\":\"000000\",\"SETTLE_AT\":\"9900\",\"TRANS_AT\":\"9900\",\"EXT_CERTIF_ID_SM3\":\"\",\"COUPON_INFO\":\"[{\\\"id\\\":\\\"3112020052714617\\\",\\\"desc\\\":\\\"5.28食用油系列产品满99元立减20元\\\",\\\"type\\\":\\\"CP01\\\",\\\"spnsrId\\\":\\\"00010000\\\",\\\"offstAmt\\\":\\\"1000\\\"},{\\\"id\\\":\\\"3112020052714617\\\",\\\"desc\\\":\\\"5.28食用油系列产品满99元立减20元\\\",\\\"type\\\":\\\"CP01\\\",\\\"spnsrId\\\":\\\"302440154110016\\\",\\\"offstAmt\\\":\\\"1000\\\"}]\",\"ORG_SYS_TRA_NO\":\"\",\"REC_CRT_TS\":\"2020-05-29 13:41:36.317455\",\"TERM_ID\":\"01080209\",\"SYS_TRA_NO\":\"547446\",\"MER_DISCOUNT\":\"1000\",\"RCV_INS_ID_CD\":\"04100000\",\"APP_VERSION\":\"1.0.0.4\",\"ORG_TRANS_IDX\":\"\",\"SUB_MCHNT_NM\":\"\",\"SETTLE_CURR_CD\":\"156\",\"POS_COND_CD\":\"00\",\"REC_UPD_TS\":\"2020-05-29 13:41:36.737534\",\"EXT_USR_RGSTR_DT\":\"20190214\",\"UP_DISCOUNT\":\"1000\",\"BUS_INFO\":\"\",\"RCV_INS_INF\":\"011\",\"ACCT_CLASS\":\"1\",\"POS_ENTRY_MD_CD\":\"042\",\"INS_PAY_MODE\":\"0\",\"TRANS_DT\":\"20200529\",\"TRANS_CURR_CD\":\"156\",\"ACQ_INS_ID_CD\":\"03025800\",\"ORG_MCHNT_ORDER_ID\":\"\",\"APP_DISCOUNT\":\"0\",\"EXT_TOKEN_ID_SM3\":\"902c9edf374f3c36c550bb8a7b3c1e36e5ac36e9a24b82132011221bf5ede4a7\",\"APP_INS_INF\":\"0100101003000000000\",\"ORDER_TYPE\":\"0135\",\"QR_CODE\":\"\",\"CERTIF_TP\":\"\",\"TRANS_TP\":\"01\",\"MCHNT_NM\":\"卜蜂莲花长兴店\",\"EXT_ACCOUNT_ID_HASH\":\"c00216062539\",\"TRANS_TM\":\"20200529134136\",\"ISS_INS_NM\":\"\",\"EXT_UPDATE_SYMBOL\":\"I\",\"CDHD_CURR_CD\":\"\",\"CARD_ATTR\":\"01\",\"ORG_TRANS_TM\":\"\",\"CONV_DT\":\"\",\"ACQ_INS_INF\":\"0100100000100000000000000\"}";
        //String string = "{\"TRANS_ID_CONV\":\"S22\",\"MSG_TP\":\"0200\",\"CARD_BIN\":\"16622298\",\"MCHNT_CD\":\"302440154110016\",\"TRANS_ST\":\"10000\",\"RELATED_ISS_INS_ID_CD\":\"\",\"ACPT_INS_ID_CD\":\"03025800\",\"LOC_TRANS_DT\":\"0529\",\"EXT_TFR_OUT_ACCT_NO_SM3\":\"\",\"RELATED_BIN\":\"\",\"EXT_TFR_IN_ACCT_NO_SM3\":\"\",\"IC_FLDS\":\"\",\"MSG_FWD_INS_ID_CD\":\"00049993\",\"AUTH_ID_RESP_CD\":\"N\",\"SETTLE_DT\":\"20200529\",\"CUPS_DEF_FLD\":\"02300000000030010000000400\",\"CUPS_CARD_IN\":\"2\",\"ISS_INS_ID_CD\":\"04105840\",\"SETTLE_MON\":\"05\",\"LOC_TRANS_TM\":\"134053\",\"RESV_FLD1\":\"0\\u0001\",\"FWD_INS_TP\":\"01\",\"RETRI_REF_NO\":\"340537389008\",\"MCHNT_TP\":\"5411\",\"EXT_PRI_ACCT_NO_SM3\":\"616563494d28571f7010a45a3a3b5753593c7dadac4540be6a511d8aa9ab61ab\",\"ORIG_TFR_DT_TM\":\"\",\"PROC_CD\":\"000000\",\"MSG_TP_CONV\":\"0200\",\"ISS_INS_TP\":\"01\",\"TRANS_AT\":\"7900\",\"ACPT_RESP_CD\":\"00\",\"CARD_CLASS\":\"01\",\"CARD_BRAND\":\"12\",\"TERM_ID\":\"01080209\",\"PBOC_IC_DATA\":\"\",\"ACPT_INS_TP\":\"01\",\"POS_COND_CD_CONV\":\"00\",\"ORIG_SYS_TRA_NO\":\"\",\"SYS_TRA_NO\":\"374702\",\"TRANS_ID\":\"S22\",\"POS_COND_CD\":\"00\",\"RCV_INS_TP\":\"01\",\"TRANS_TP_ID\":\"0\",\"CARD_ACCPTR_NM_LOC\":\"卜蜂莲花长兴店\",\"POS_ENTRY_MD_CD\":\"042\",\"TRANS_CURR_CD\":\"156\",\"EXT_PRI_ACCT_NO_CONV_SM3\":\"616563494d28571f7010a45a3a3b5753593c7dadac4540be6a511d8aa9ab61ab\",\"MSG_RCV_INS_ID_CD\":\"04100000\",\"PROC_CD_CONV\":\"000000\",\"TRANS_MEDIA\":\"5\",\"TRANS_CHNL\":\"03\",\"TRANS_TP\":\"S220000000\",\"TFR_DT_TM\":\"0529134054\",\"CUPS_SIG_CARD_IN\":\"1\",\"EXT_UPDATE_SYMBOL\":\"I\",\"CARD_ATTR\":\"01\",\"CROSS_DIST_IN\":\"0\",\"SETTLE_D\":\"29\"}";
        ProducerRecord<String,String> record = new ProducerRecord<String,String>("01QRC",string);

        producer.send(record, new Callback() {
            @Override
            public void onCompletion(RecordMetadata metadata, Exception exception) {
                if(null==exception){
                    System.out.println("perfect!");
                }
                if(null!=metadata){
                    System.out.print("offset:"+metadata.offset()+";partition:"+metadata.partition());
                }
            }
        }).get();
        producer.close();

    }

}
